<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<div id="host"></div>
<script>
description("Tests to ensure that ShadowRoot.getElementById works even after mutation");

var host = document.getElementById("host");
var shadow = host.attachShadow({mode: 'open'});

shouldBe("null", "shadow.getElementById('foo')");

e0a = document.createElement("div");
e0a.id = "foo";
shadow.appendChild(e0a);
shouldBe("e0a", "shadow.getElementById('foo')");

e0b = document.createElement("span");
e0b.id = "foo";
shadow.insertBefore(e0b, e0a);
shouldBe("e0b", "shadow.getElementById('foo')");

e0c = document.createElement("p");
e0c.id = "foo";
e0cParent = document.createElement("div");
e0cParent.appendChild(e0c);
shadow.insertBefore(e0cParent, e0b);
shouldBe("e0c", "shadow.getElementById('foo')");

shadow.removeChild(e0cParent);
shouldBe("e0b", "shadow.getElementById('foo')");
shadow.removeChild(e0b);
shouldBe("e0a", "shadow.getElementById('foo')");
shadow.removeChild(e0a);
shouldBe("null", "shadow.getElementById('foo')");
</script>
</body>
</html>
